Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xoffsets kwarg #214

Merged
merged 4 commits into from
Apr 1, 2025
Merged

Add xoffsets kwarg #214

merged 4 commits into from
Apr 1, 2025

Conversation

scottshambaugh
Copy link
Contributor

@scottshambaugh scottshambaugh commented Mar 7, 2025

Closes #176 by adding xoffsets as a kwarg, similar to yoffsets. Properly handles both numeric and timedelta offsets.

@scottshambaugh scottshambaugh marked this pull request as ready for review March 7, 2025 16:49
@scottshambaugh
Copy link
Contributor Author

scottshambaugh commented Mar 7, 2025

This lets me get a plot like I was wanting in the original issue!

import matplotlib.pyplot as plt
import numpy as np
from labellines import labelLines

pi_2 = np.pi/2
x = np.linspace(0, pi_2, 100)
fig, ax = plt.subplots()

for i in range(3):
    ax.plot(x, np.sin(x) + i, label=f'x{i}')
labelLines(ax.get_lines(), zorder=2.5, xvals=(pi_2 - 1e-12), xoffsets=0.1)
ax.set_xlim(0, pi_2 + 0.2)

test

@@ -162,6 +179,13 @@ def _update_anchors(self):
x = self._line.convert_xunits(self._target_x)
xdata, ydata = normalize_xydata(self._line)

# Convert timedelta to float if needed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self, can update when matplotlib/matplotlib#8869 is resolved.

@cphyc cphyc merged commit 2b14be6 into cphyc:main Apr 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: allow plotting a labelLine outside the data range
2 participants